package com.hisan.waimaidao.carvas;


import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;


public class MyGroup extends ViewGroup {
    public MyGroup(Context context) {
        super(context);
    }

    public MyGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyGroup(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onLayout(boolean b, int i, int i1, int i2, int i3) {
        if (getChildCount()>0){
            //获取子控件
            View view=getChildAt(0);
            //获取当前子控件宽高度,之后设置左上右下的位置
            view.layout(20,20,view.getMeasuredWidth()+20,view.getMeasuredHeight()+20);
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (getChildCount()>0){
            View view=getChildAt(0);
            /**
             * 测量当前view的大小
             * view :测量的子控件
             * 父控件的宽度和高度
             */
            measureChild(view,widthMeasureSpec,heightMeasureSpec);
        }
    }
}
